<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>文章</title>

</head>
<body>
<jsp:include page="/incloud/header.jsp" />

<div class="d-flex align-items-stretch">

    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp" />

    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">发布文章</h2>
            </div>
        </div>

        <section class="no-padding-bottom">

            <div class="list-group myList">
                <!--搜索文章的条件-->
                <div class="myTitle">
                    <form class="form-inline">
                        <div class="form-group">
                            <label for="inlineFormInput" class="sr-only">Name</label>
                            <input id="inlineFormInput" value="${title}" type="text" placeholder="按标题名字查找" class="mr-sm-3 form-control">
                        </div>
                        <div class="form-group">
                            <input type="button" onclick="search()" value="查询" class="btn btn-primary">
                        </div>
                    </form>

                    <input id = "addArt" type="submit" value="发布文章" class="btn btn-primary">

                </div>

                <ul>
                    <c:forEach items="${articleList}" var="article" varStatus="status">
                    <li class="list-group-item">
                        <div style="float: right;">
                            <span><strong>收藏数：</strong>${article.collectCount}</span>
                            <span>&nbsp;</span>
                            <span>&nbsp;</span>
                            <span>&nbsp;</span>
                            <span><strong>浏览数：</strong>${article.browse_count}</span>
                        </div>
                        <a href="/article/lookArticleInfo?id=${article.id}">${article.title}</a>
                        <p class="h6"><strong>作者：</strong>${article.publish_real_name}</p>
                        <p class="h6"><strong>时间：</strong>${article.publish_date}</p>
                        <p style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis">${article.content}</p>
                    </li>
                    </c:forEach>
                </ul>

                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <c:if test="${articlePageUtils.pageCount > 0}">
                        <li>
                            <a href="javascript:0;" onclick="pre(${articlePageUtils.cureePage})" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="1" end="${articlePageUtils.pageCount}" varStatus="status">
                        <li><a href="/article/findAll?cureePage=${status.count}&title=${title}">${status.count}</a></li>
                        </c:forEach>
                        <li>
                            <a href="javascript:0;" onclick="next(${articlePageUtils.cureePage})" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        </c:if>
                    </ul>
                </nav>
            </div>
        </section>


        <jsp:include page="/incloud/footer.jsp" />
    </div>
</div>

</body>
</html>
<script type="text/javascript">
    $("#avatar").click(function () {
        location.href = "/user/detail?id=${loginUser.id}";
    })
    //根据文章名模糊查询文章信息
    function search() {

        var searchName = $("#inlineFormInput").val();
        location.href = "/article/findAll?cureePage=1&title="+searchName;
    }
    //上一页
    function pre(cureePage){
        if(cureePage - 1 < 1){
            layer.msg("已经是第一页了")
            return;
        }
        //cureePage = cureePage -1 ;
        location.href = "/article/findAll?cureePage="+(cureePage-1)+"&title="+$("#inlineFormInput").val();
    }
    //下一页
    function next(cureePage){
        if(cureePage +1 > ${articlePageUtils.pageCount}){
            layer.msg("已经是最后一页了")
            return;
        }
        //cureePage = cureePage +1 ;
        location.href = "/article/findAll?cureePage="+(cureePage+1)+"&title="+$("#inlineFormInput").val();
    }
	//添加文章跳转链接
	$("#addArt").click(function () {
	    window.location.href = '/html/article_add.jsp'
	});


</script>